#pragma once
#include "pch.h"
#include <string>
#include <vector>
#include <boost\algorithm\string.hpp>
#include <boost\lexical_cast.hpp>
static std::string Unicode2Ansi(const std::wstring& unicodeStr)
{
	std::string retStr("");
	int strLen = (int)::WideCharToMultiByte(CP_ACP, NULL, unicodeStr.c_str(), (int)wcslen(unicodeStr.c_str()), NULL, 0, NULL, NULL);
	if (strLen == 0)
		return retStr;
	std::vector<char> strBuffer(strLen, '\0');
	::WideCharToMultiByte(CP_ACP, NULL, unicodeStr.c_str(), (int)wcslen(unicodeStr.c_str()), &strBuffer[0], strLen, NULL, NULL);

	retStr.assign(strBuffer.begin(), strBuffer.end());
	return retStr;
}

static void TrimString(std::vector<std::wstring>& vStr)
{
	for (size_t t = 0; t < vStr.size(); ++t)
	{
		boost::trim(vStr[t]);
	}
}
static std::vector<std::wstring> SplitString(std::wstring strTarget, std::wstring strSeperator,
	boost::algorithm::token_compress_mode_type type = boost::token_compress_on, bool m_bTrim = true)
{
	std::vector<std::wstring> vSplitRslt;
	boost::split(vSplitRslt, strTarget, boost::is_any_of(strSeperator), type);
	if (m_bTrim)
	{
		TrimString(vSplitRslt);
	}
	return vSplitRslt;
}
static CString Utf82TChar(const std::string&str)
{
	CString cStr(str.c_str());
	return cStr;
}
static CString Unicode2TChar(const std::wstring&wstr)
{
	std::string str = Unicode2Ansi(wstr);
	CString cStr = Utf82TChar(str);
	return cStr;
}
static std::wstring Utf8ToUnicode(const std::string& str)
{
	std::wstring tmpStr(L"");
	int wcsLen = ::MultiByteToWideChar(CP_UTF8, NULL, str.c_str(), (int)strlen(str.c_str()), NULL, 0);
	if (wcsLen <= 0)
		return tmpStr;
	std::wstring retWstr(wcsLen, '\0');
	::MultiByteToWideChar(CP_UTF8, NULL, str.c_str(), (int)strlen(str.c_str()), &retWstr[0], wcsLen);

	return retWstr;
}
static std::wstring AnsiToUnicode(const std::string& str)
{
	std::wstring tmpStr(L"");
	int wcsLen = ::MultiByteToWideChar(CP_ACP, NULL, str.c_str(), (int)strlen(str.c_str()), NULL, 0);
	if (wcsLen <= 0)
		return tmpStr;
	std::wstring retWstr(wcsLen, '\0');
	::MultiByteToWideChar(CP_ACP, NULL, str.c_str(), (int)strlen(str.c_str()), &retWstr[0], wcsLen);
	return retWstr;
}